package regexp.homework;

/**
 * @author DCSGO
 * @version 1.0
 * 要求验证是不是整数或者小数
 * 提示: 这个题要考虑正数和负数
 * 比如: 123 -345 34.89 -87.9 -0.01 0.45 等
 */
public class Homework2 {
    public static boolean isDecimal(String num) {
        return num.matches("^[+-]?([1-9]\\d*|0)(\\.\\d+)?$");
        //return num.matches("^[+-]?(([1-9]\\d*)|0)(\\.\\d+)?$");
    }

    public static void main(String[] args) {
        System.out.println(isDecimal("3.145"));//true
        System.out.println(isDecimal("3.14.5"));//false
        System.out.println(isDecimal("-3456"));//true
        System.out.println(isDecimal("-3456."));//false
        System.out.println(isDecimal("-3.45"));//true
        System.out.println(isDecimal(".45"));//false
        System.out.println(isDecimal("-.45"));//false
        System.out.println(isDecimal("00001"));//false
        System.out.println(isDecimal("+1"));//true
        System.out.println(isDecimal("+0.0001"));//true
        System.out.println(isDecimal("0.00"));//true
        System.out.println(isDecimal("01.01"));//false
    }
}
